package qqmeeting

import (
	"encoding/json"
	"errors"
	"fmt"
)

//UpdateMeetingBody 修改会议提交参数
type UpdateMeetingBody struct {
	MeetingID  string                 `json:"-"`
	Userid     string                 `json:"userid"`
	Instanceid int                    `json:"instanceid"`
	Subject    string                 `json:"subject"`
	Hosts      []UserObj              `json:"hosts"`
	Invitees   []UserObj              `json:"invitees"`
	StartTime  string                 `json:"start_time"`
	EndTime    string                 `json:"end_time"`
	Password   string                 `json:"password"`
	Settings   map[string]interface{} `json:"settings"`
}

//UpdateMeetingResponse 修改会议响应结果
type UpdateMeetingResponse struct {
	Response
	MeetingNumber   int                 `json:"meeting_number"`
	MeetingInfoList []UpdateMeetingInfo `json:"meeting_info_list"`
}

//MeetingInfo 会议对象
type UpdateMeetingInfo struct {
	MeetingID   string `json:"meeting_id"`
	MeetingCode string `json:"meeting_code"`
}

//UpdateMeeting 创建会议
func (c *Client) UpdateMeeting(body UpdateMeetingBody) (resp UpdateMeetingResponse, err error) {
	uri := fmt.Sprintf("/v1/meetings/%s", body.MeetingID)
	var statusCode int
	var content []byte
	if statusCode, content, err = c.PUT(uri, body); err != nil {
		return
	}
	if content != nil {
		if err = json.Unmarshal(content, &resp); err != nil {
			err = errors.New(err.Error() + "\n" + string(content))
		}
	} else {
		err = fmt.Errorf("[%d] Bad request", statusCode)
	}
	resp.StatusCode = statusCode
	return
}
